package cn.edu.zzuli.nothinglink.controller;


import cn.edu.zzuli.nothinglink.anno.CurrentUser;
import cn.edu.zzuli.nothinglink.entity.R;
import cn.edu.zzuli.nothinglink.service.ProblemService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author suzyyy
 * @since 2021-04-08
 */
@RestController
@RequestMapping("/problem")
public class ProblemController {

    @Autowired
    ProblemService problemService;

    @PostMapping("/pub/{stream}")
    public R putProblem(@PathVariable String stream, @RequestBody JSONObject json) {
        if (json.get("checkInfos") != null && !StringUtils.isEmpty(json.get("content"))) {
            return problemService.publishProblem2TheStuClients(stream, json);
        }
        return R.error().add("error", "发布问题失败，请检查参数！");
    }

    @GetMapping("/condition/my")
    public R getSignInfo(@CurrentUser Integer teaId) {
        if (teaId == null) return R.error().add("error", "请先登陆");
        return problemService.getProblemCondition(teaId);
    }

}

